import { Column, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn } from 'typeorm'
import { User } from '../user/user.entity'
import { Menus } from '../menus/menus.entity'
import { Exclude } from 'class-transformer'

@Entity()
export class Roles {
  // Expose：哪些字段需要暴露，Exclude：哪些字段不需要暴露
  @PrimaryGeneratedColumn()
  @Exclude()
  id: number
  @Column()
  name: string

  //   多对多
  @ManyToMany(() => User, (user) => user.roles, { onDelete: 'CASCADE' })
  user: User[]

  // 多对多：menus
  @ManyToMany(() => Menus, (menus) => menus.roles)
  @JoinTable({ name: 'roles_menus' })
  menus: Menus[]
}
